package com.ymttest.database.sqlwapper;

import java.util.List;

import org.apache.commons.lang.math.RandomUtils;

import com.ymt.core.tool.Logger;
import com.ymt.database.SqlManager;
import com.ymttest.database.model.YmtAppTuanTemplate;
import com.ymttest.utils.EnvSetup;

/**
 * APP 团模板
 * 
 * @author wanghuiyong
 * @date:2015-06-12
 */
public class YmtAppTuanTemplateWapper {
	SqlManager manage;

	public YmtAppTuanTemplateWapper() {
		manage = new SqlManager("ymt" + EnvSetup.getEnv());
	}

	/**
	 * 随机获取一条APP模板信息
	 * 
	 * @return YmtAppTuanTemplate
	 */
	public YmtAppTuanTemplate getRandomTemplateInfo() {
		List<YmtAppTuanTemplate> num = manage.getSelectResults(
				"com.ymttest.database.mapping.YmtAppTuanTemplateMapper.selectNum", null);
		int MaxNum = num.get(0).getItopicid();// 数据库记录总条数
		int tempNum = RandomUtils.nextInt(MaxNum);
		while (tempNum == 0) {
			tempNum = RandomUtils.nextInt(MaxNum);
		}
		List<YmtAppTuanTemplate> num2 = manage.getSelectResults(
				"com.ymttest.database.mapping.YmtAppTuanTemplateMapper.selectByRowId", RandomUtils.nextInt(MaxNum));
		return num2.get(0);
	}

	public static void main(String[] args) {
		YmtAppTuanTemplateWapper test = new YmtAppTuanTemplateWapper();
		YmtAppTuanTemplate a = test.getRandomTemplateInfo();
		Logger.debug(a.getItopicid());
	}
}